/* jshint esversion: 6 */

export function encodeFormString(param, parentKey = null) {
    let paramStr = "";
    if (['string','number','boolean'].includes(typeof param)) {
        paramStr += `&${parentKey}=${encodeURIComponent(param)}`;
    } else if(param instanceof Object){
        for(let _key in param){
            let _val=param[_key];
            var k = parentKey === null ? _key : parentKey + `[${_key}]`;
            paramStr += '&' + encodeFormString(_val, k);
        }
    }else{ throw `${param} is not encodable`; }
    return paramStr.slice(1);
}